package com.cloud.controller;

import com.cloud.service.PayService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class PayController {

    @Autowired
    private PayService payService;

    @Autowired
    private RestTemplate restTemplate;

    //http://localhost:8012/save
    @GetMapping("/save")
    //Seata分布式事务
    @GlobalTransactional
    public String save() {
        //支付业务
        this.payService.save();
        int i = 10/0;

        //修改订单
        this.restTemplate.getForObject("http:localhost:8011/save", String.class);
        return "success";

    }
}
